import { defineStore } from "pinia";
import { ref } from "vue";

export const useConfigStore = defineStore("config", () => {
  // 状态
  const requestConfig = ref({
    requestInterval: 1000,
    retryCount: 3,
    retryInterval: 1000,
    concurrentRequests: 3,
    timeout: 5000,
    autoRetry: true,
    headers: {
      "User-Agent": "Mozilla/5.0",
      "Content-Type": "application/json",
    },
  });

  // 方法
  const updateRequestConfig = (config) => {
    Object.assign(requestConfig.value, config);
  };

  const resetRequestConfig = () => {
    requestConfig.value = {
      requestInterval: 1000,
      retryCount: 3,
      retryInterval: 1000,
      concurrentRequests: 3,
      timeout: 5000,
      autoRetry: true,
      headers: {
        "User-Agent": "Mozilla/5.0",
        "Content-Type": "application/json",
      },
    };
  };

  return {
    requestConfig,
    updateRequestConfig,
    resetRequestConfig,
  };
});
